package com.powersi.biz.base.dao;

import java.util.List;

import com.powersi.biz.entity.Item;
import com.powersi.hygeia.framework.BaseDAOImpl;
import com.powersi.hygeia.framework.util.DAOHelper;
import com.powersi.hygeia.framework.util.DBHelper;

public class ItemDAOImpl extends BaseDAOImpl implements ItemDAO{

	@Override
	public List getItemList(Item item) {
		
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select b.SORT_NAME,a.* from bs_item a,bs_device_sort b where a.device_sort_id = b.id ");
		
		if(item != null){
			if(item.getDevice_sort_id() != null && item.getDevice_sort_id() > 0 ){
				sb.append(" and a.device_sort_id = "+ item.getDevice_sort_id());
			}
			if(item.getItem_name() != null && item.getItem_name() != "" ){
				sb.append(" and a.item_name like '%"+ item.getItem_name() + "%'");
			}
		}
		
		sb.append(" order by a.device_sort_id");
		
		return DBHelper.executeList(sb.toString());
	}

	@Override
	public Item getItem(Item item) {
		
		String s = " select * from bs_item where 1=1 ";
		if(item != null){
			s+= " and id = "+ item.getId();
		}
		
		s+= " order by device_sort_id";
		return DBHelper.executeBean(Item.class, s);
	}

	@Override
	public int insertItem(Item item) {
		return DAOHelper.insert("bs_item", item);
	}

	@Override
	public int updateItem(Item item) {
		return DAOHelper.update("bs_item",item );
	}

}
